//
//  WBMainNavigationController.swift
//  盈微博
//
//  Created by hoterzhang on 2018/1/20.
//  Copyright © 2018年 hoterzhang. All rights reserved.
//

import UIKit

class WBMainNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏默认的NavigationBar 自定义NavigationBar 在BaseViewController中
        navigationBar.isHidden = true
    }

    // MARK: - 重写push
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //隐藏底部的TabBar
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            //设置返回
            if let vc = viewController as? WBBaseViewController {
                
                var title = "返回"
                //判断返回的级数
                if childViewControllers.count == 1 {
                    //title 显示首页的标题
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                //取出自定义navitem
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent), isBack: true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func popToParent(){
        popViewController(animated: true)
    }

}
